Release 10.1A: OpenEdge Development:
Programming Interfaces


Envelope information example

Here is an example of a simple SAX-writer application that creates envelope information.

/* Program to write an envelope address */ 
DEFINE VARIABLE hSAXWriter AS HANDLE. 
CREATE SAX-WRITER hSAXWriter. 
hSAXWriter:FORMATTED = TRUE. /* Format output so it is easy to read */ 
hSAXWriter:SET-OUTPUT-DESTINATION("file", "mailing.xml"). 
hSAXWriter:START-DOCUMENT(). 
/* The ENCODING           attribute defaults to UTF-8 */ 
/* The FRAGMENT           attribute defaults to FALSE */ 
/* The STRICT             attribute defaults to TRUE  */ 
hSAXWriter:START-ELEMENT(psc:"mailingaddress"). 
hSAXWriter:DECLARENAMESPACE(“www.progress.com”, “psc”). 
RUN xmlData(INPUT "name", INPUT "John Smith"). 
hSAXWriter:START-ELEMENT("psc:address").  
hSAXWriter:INSERT-ATTRIBUTE("type", "personal") /* Node has an attribute */ 
RUN xmlData(INPUT "psc:street",  INPUT "411 Whatsup St."). 
RUN xmlData(INPUT "psc:city",    INPUT "Somerville"). 
RUN xmlData(INPUT "psc:state",   INPUT "MA"). 
RUN xmlData(INPUT "psc:zipcode", INPUT "02143"). 
hSAXWriter:END-ELEMENT("psc:address"). 
hSAXWriter:START-ELEMENT("psc:address").  
hSAXWriter:INSERT-ATTRIBUTE("type", "business") 
RUN xmlData(INPUT "psc:name",   INPUT "Progress Software"). 
RUN xmlData(INPUT "psc:street", INPUT "14 Oak Park"). 
RUN xmlData(INPUT "psc:city",   INPUT "Bedford"). 
RUN xmlData(INPUT "psc:state",  INPUT "MA"). 
RUN xmlData(INPUT "psc:zip",    INPUT "01730"). 
hSAXWriter:END-ELEMENT("psc:address"). 
hSAXWriter:WRITE-EMPTY-ELEMENT("psc:default").  
hSAXWriter:INSERT-ATTRIBUTE("type", "personal") 
hSAXWriter:END-ELEMENT("psc:mailingaddress"). 
hSAXWriter:END-DOCUMENT(). /* Document written to working directory. */ 
PROCEDURE xmlData: 
DEFINE INPUT PARAMETER xmlNode AS CHARACTER. 
DEFINE INPUT PARAMETER charData AS CHARACTER. 
	hSAXWriter:START-ELEMENT(xmlNode). 
	hSAXWriter:WRITE-CHARACTERS(charData). 
	hSAXWriter:END-ELEMENT(xmlNode). 
END PROCEDURE. 

This code produces a document like the following:

<?xml version=”1.0”> 
<psc:mailingaddress xmlns:psc=”www.progress.com”> 
    <psc:name>John Smith</psc:name> 
    <psc:address type="personal"> 
        <psc:street>411 Whatsup St.</psc:street> 
        <psc:city>Somerville</psc:city> 
        <psc:state>MA</psc:state> 
        <psc:zipcode>02143</psc:zipcode> 
    </psc:address> 
    <psc:name>John Smith</psc:name> 
    <psc:address type="business"> 
        <psc:name>Progress Software</psc:name> 
        <psc:street>14 Oak Park Drive</psc:street> 
        <psc:city>Bedford</psc:city> 
        <psc:state>MA</psc:state> 
        <psc:zipcode>01730</psc:zipcode> 
    </psc:address> 
    <psc:default type="personal"/> 
</psc:mailingaddress> 

Alternately, instead of creating an internal procedure, use the built in method for creating a leaf node.

/* Program to write an envelope address */ 
DEFINE VARIABLE hSAXWriter AS HANDLE. 
CREATE SAX-WRITER hSAXWriter. 
hSAXWriter:FORMATTED = TRUE. /* Format output so it is easy to read */ 
hSAXWriter:SET-OUTPUT-DESTINATION("file", "mailing.xml"). 
hSAXWriter:START-DOCUMENT(). 
/* The ENCODING           attribute defaults to UTF-8 */ 
/* The FRAGMENT           attribute defaults to FALSE */ 
/* The STRICT             attribute defaults to TRUE  */ 
hSAXWriter:START-ELEMENT(psc:"mailingaddress"). 
hSAXWriter:DECLARENAMESPACE(“www.progress.com”, “psc”). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:name", "John Smith"). 
hSAXWriter:START-ELEMENT("psc:address").  
hSAXWriter:INSERT-ATTRIBUTE("type", "personal") /* Node has an attribute */ 
hSAXWriter:WRITE-DATA-ELEMENT("psc:street",  "411 Whatsup St."). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:city",    "Somerville"). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:state",   "MA"). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:zipcode", "02143"). 
hSAXWriter:END-ELEMENT("psc:address"). 
hSAXWriter:START-ELEMENT("psc:address").  
hSAXWriter:INSERT-ATTRIBUTE("type", "business"). /* Node has an attribute */ 
hSAXWriter:WRITE-DATA-ELEMENT("psc:name",   "Progress Software"). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:street", "14 Oak Park"). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:city",   "Bedford"). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:state",  "MA"). 
hSAXWriter:WRITE-DATA-ELEMENT("psc:zip",    "01730"). 
hSAXWriter:END-ELEMENT("psc:address"). 
hSAXWriter:WRITE-EMPTY-ELEMENT("psc:default"). 
hSAXWriter:INSERT-ATTRIBUTE("type", "personal"). 
hSAXWriter:END-ELEMENT("psc:mailingaddress"). 
hSAXWriter:END-DOCUMENT(). /* Document written to working directory. */ 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095